class MapController < ApplicationController

def index
  region = 'Genesis'
  queue = Solarsystem.find_by_region(region)
	start = Solarsystem.find_by_name('Menai')
  stop = Solarsystem.find_by_name('Chej')
  entf = Math::sqrt((start.x - stop.x)**2 + (start.y - stop.y)**2 + (start.z - stop.z)**2)
  cur = start
  while(cur.name != stop.name)
    if cur.hub?
      
    else if cur.corridor
      
    end
    end
  
  end
end

def graph
  systems = Solarsystem.find(:all, :conditions => ["region_id = ? OR region_id = ? OR region_id = ?", Region.find_by_name("Genesis").id, Region.find_by_name("Kor-Azor").id, Region.find_by_name("Aridia").id])  
  @skips = ["Abath", "Vecamia", "Ahbazon", "Nardiarang", "Leran", "Beke", "Assez", "Alal",
           "Zarer","Makhwasan","Assez","Ziasad", "Nardiarang", "Chamja", "Dom-Aphis", "Toon",
           "Hesarid", "Schmaeel", "Abath", "Mafra", "Arzi", "Perbhe", "Oguser", "Kerying",
           "Zorenyen"]
  dot = File.new('D:\graph.dot', 'w')
  render_text "done!", :layout => false
  dot.write("digraph G {\n")
  dot.write("node [shape=none]\n")
  dot.write("spline=true\n")
  @done = Hash.new([])
 # @kills = Kill.kills
  systems.each do |sys|
    next if sys.highsec? || @skips.index(sys.name)
    @done[sys.name] = Array.new()
    
    sys.gates.each do |gate|
      next if @done[gate.name].index(sys.name) || @done[sys.name].index(gate.name)
        
      gateLabel = []
      sysLabel = []
  
      if gate.highsec?
        gateLabel.push("label = <<font color=\"red\">"+ gate.name + "</font>>")
      else
        gateLabel.push('label = "' + gate.name + '"')      
      end
      sysLabel.push('label = "' + sys.name + '"')      
#      gateLabel.push('fontsize="'+(10 + @kills[gate.id].to_i).to_s + '"')
#      sysLabel.push('fontsize="'+(10 + @kills[sys.id].to_i).to_s + '"')
      
      
      dot.write(cleanup(sys.name) + ' [ ' + sysLabel.join(" ") + "];\n")
      dot.write(cleanup(gate.name) + ' [ ' + gateLabel.join(" ") + "];\n")

      dot.write(cleanup(sys.name) + " -> " + cleanup(gate.name) + " [dir = none] \n")
      @done[sys.name].push(gate.name)
    end
  end
  dot.write("}\r\n")
  dot.close
end

def cleanup(name)
    tmp = name.gsub(/\s/, "_")
    tmp.gsub!(/\-/, "_")
    tmp.gsub(/\d/, "xx")
end



end
